package com.jeeplus.modules.api.common;


import java.text.SimpleDateFormat;
import java.util.Random;

/**
 * uuid生成工具
 */
public class UUIDUtils {

    /**
     * 6位数字字符串
     * @param len 长度
     * @return 数字
     */
    public synchronized static String uuid(int len) {
        StringBuilder code = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < len; i++) {
            int r = random.nextInt(10);
            code.append(r);
        }
        return code.toString();
    }

    /**
     * 订单号生成
     * @param len 时间加随机长度
     * @return 单号
     */
    public synchronized static String orderUuid(int len) {
        StringBuilder code = new StringBuilder();
        Random random = new Random();
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
        for (int i = 0; i < len; i++) {
            int r = random.nextInt(10);
            code.append(r);
        }
        return sf.format(System.currentTimeMillis()) + code.toString();
    }

    public static void main(String[] args) {
        String s = orderUuid(6);
        String uuid = uuid(6);
        System.out.println(s);
        System.out.println(uuid);
    }
}